/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package CAPA_INTERFAZ_DE_USUARIO;

import CAPA_LOGICA_DE_NEGOCIO.LN_LOGICA_NEGOCIO;
import RECURSOS.ERROR;
import RECURSOS.FACTURA;
import RECURSOS.FONDO_FORM;
import RECURSOS.LOG;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JOptionPane;

/**
 *
 * @author Gis
 */
public class IU_NUMERO_FAC extends javax.swing.JFrame {

    private LN_LOGICA_NEGOCIO  obj_ln;
    private FONDO_FORM F;

    @Override    
    public Image getIconImage() {
        Image retValue = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("RECURSOS/SOVI.PNG"));
        return retValue;
    }

    public IU_NUMERO_FAC() {
        initComponents();            
        this.setLocationRelativeTo(null);
        obj_ln = new LN_LOGICA_NEGOCIO();
               
        F=new FONDO_FORM(this.getWidth(),this.getHeight(),"fondo.png");
        this.add(F);
        this.pack();                
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea2 = new javax.swing.JTextArea();
        btn_cancelar = new javax.swing.JButton();
        btn_buscar = new javax.swing.JButton();
        txt_num_fac = new javax.swing.JTextField();
        lbl_numfactura = new javax.swing.JLabel();
        lbl_titulo = new javax.swing.JLabel();
        btn_cancelar1 = new javax.swing.JButton();
        btn_guardar = new javax.swing.JButton();

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        jTextArea2.setColumns(20);
        jTextArea2.setRows(5);
        jScrollPane2.setViewportView(jTextArea2);

        btn_cancelar.setFont(new java.awt.Font("Cambria", 0, 14)); // NOI18N
        btn_cancelar.setForeground(new java.awt.Color(0, 0, 102));
        btn_cancelar.setText("CANCELAR");
        btn_cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_cancelarActionPerformed(evt);
            }
        });

        btn_buscar.setFont(new java.awt.Font("Cambria", 0, 14)); // NOI18N
        btn_buscar.setForeground(new java.awt.Color(0, 0, 102));
        btn_buscar.setText("BUSCAR");
        btn_buscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_buscarActionPerformed(evt);
            }
        });

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("SOVI");
        setIconImage(getIconImage());

        txt_num_fac.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txt_num_facActionPerformed(evt);
            }
        });
        txt_num_fac.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txt_num_facKeyTyped(evt);
            }
        });

        lbl_numfactura.setBackground(new java.awt.Color(255, 255, 255));
        lbl_numfactura.setFont(new java.awt.Font("Cambria", 0, 14)); // NOI18N
        lbl_numfactura.setForeground(new java.awt.Color(0, 0, 102));
        lbl_numfactura.setText("N.- Factura");

        lbl_titulo.setFont(new java.awt.Font("Cambria", 1, 18)); // NOI18N
        lbl_titulo.setForeground(new java.awt.Color(0, 0, 112));
        lbl_titulo.setText("ASIGNACIÓN  DE NUMERACIÓN DE FACTURAS");

        btn_cancelar1.setFont(new java.awt.Font("Cambria", 0, 14)); // NOI18N
        btn_cancelar1.setForeground(new java.awt.Color(0, 0, 102));
        btn_cancelar1.setText("CANCELAR");
        btn_cancelar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_cancelar1ActionPerformed(evt);
            }
        });

        btn_guardar.setFont(new java.awt.Font("Cambria", 0, 14)); // NOI18N
        btn_guardar.setForeground(new java.awt.Color(0, 0, 102));
        btn_guardar.setText("GUARDAR");
        btn_guardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_guardarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(77, 77, 77)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(btn_guardar)
                                .addGap(107, 107, 107)
                                .addComponent(btn_cancelar1))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(lbl_numfactura)
                                .addGap(18, 18, 18)
                                .addComponent(txt_num_fac, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(50, 50, 50))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(49, 49, 49)
                        .addComponent(lbl_titulo)))
                .addContainerGap(49, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(lbl_titulo)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txt_num_fac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_numfactura))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btn_cancelar1)
                    .addComponent(btn_guardar))
                .addContainerGap(26, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btn_cancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_cancelarActionPerformed
        this.dispose();
    }//GEN-LAST:event_btn_cancelarActionPerformed

    private void btn_buscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_buscarActionPerformed

    }//GEN-LAST:event_btn_buscarActionPerformed

    private void btn_cancelar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_cancelar1ActionPerformed
        this.dispose();
    }//GEN-LAST:event_btn_cancelar1ActionPerformed

    private void btn_guardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_guardarActionPerformed
       
        if(!this.txt_num_fac.getText().isEmpty()){          
            FACTURA fac = new FACTURA();  
            fac.setError(new ERROR());
            obj_ln.guardarnumFac(fac, Integer.parseInt(this.txt_num_fac.getText()));                        
            if(fac.getError().getDescripcion_error()== null)
            {            
                JOptionPane.showMessageDialog(null,"Asignación Exitosa!","Numeración de Facturas",JOptionPane.INFORMATION_MESSAGE);                                        
                this.dispose();
            }
            else                       
            {
                LOG l=new LOG();                
                JOptionPane.showMessageDialog(null,obj_ln.error_usuario(fac.getError()),"ERROR",JOptionPane.ERROR_MESSAGE);
                String log="Tipo: "+fac.getError().getTipo_error()+". Mensaje: "+fac.getError().getDescripcion_error();
                l.escribir(log);                                 
            }
        }
        else
        {
            JOptionPane.showMessageDialog(null,"Ingrese un valor","ERROR",JOptionPane.ERROR_MESSAGE);
        }
      
      
      
    }//GEN-LAST:event_btn_guardarActionPerformed

    private void txt_num_facActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_num_facActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txt_num_facActionPerformed

    private void txt_num_facKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_num_facKeyTyped
        // TODO add your handling code here:
        char car = evt.getKeyChar();
        if((car<'0' || car>'9')) evt.consume();
    }//GEN-LAST:event_txt_num_facKeyTyped

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(IU_NUMERO_FAC.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(IU_NUMERO_FAC.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(IU_NUMERO_FAC.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(IU_NUMERO_FAC.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new IU_NUMERO_FAC().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_buscar;
    private javax.swing.JButton btn_cancelar;
    private javax.swing.JButton btn_cancelar1;
    private javax.swing.JButton btn_guardar;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextArea jTextArea2;
    private javax.swing.JLabel lbl_numfactura;
    private javax.swing.JLabel lbl_titulo;
    private javax.swing.JTextField txt_num_fac;
    // End of variables declaration//GEN-END:variables
}
